package com.project.platform.service.impl;

import com.project.platform.entity.CheckinApplication;
import com.project.platform.entity.CheckoutApplication;
import com.project.platform.mapper.CheckoutApplicationMapper;
import com.project.platform.mapper.ElderMapper;
import com.project.platform.service.CheckoutApplicationService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import com.project.platform.vo.PageVO;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * ${table.name}
 */
@Service
public class CheckoutApplicationServiceImpl  implements CheckoutApplicationService {
    @Resource
    private CheckoutApplicationMapper checkoutApplicationMapper;

    @Resource
    private ElderMapper elderMapper;
    
    @Override
    public PageVO<CheckoutApplication> page(Map<String, Object> query, Integer pageNum, Integer pageSize) {
        PageVO<CheckoutApplication> page = new PageVO();
        List<CheckoutApplication> list = checkoutApplicationMapper.queryPage((pageNum - 1) * pageSize, pageSize, query);
        page.setList(list);
        page.setTotal(checkoutApplicationMapper.queryCount(query));
        return page;
    }

    @Override
    public CheckoutApplication selectById(Integer id) {
        CheckoutApplication checkoutApplication = checkoutApplicationMapper.selectById(id);
        return checkoutApplication;
    }

    @Override
    public List<CheckoutApplication> list() {
        return checkoutApplicationMapper.list();
    }
    @Override
    public void insert(CheckoutApplication entity) {
        check(entity);
        checkoutApplicationMapper.insert(entity);
    }
    @Override
    public void updateById(CheckoutApplication entity) {
        check(entity);
        checkoutApplicationMapper.updateById(entity);
    }
    private void check(CheckoutApplication entity) {

    }
    @Override
    public void removeByIds(List<Integer> ids) {
        checkoutApplicationMapper.removeByIds(ids);
    }

    @Override
    public CheckoutApplication getByElder(Integer id) {
        return checkoutApplicationMapper.getByElder(id);
    }

    @Override
    public void approve(CheckoutApplication entity) {
        check(entity);
        if (Objects.equals(entity.getStatus(), "1")) {
            elderMapper.updateBuildingIdAndRoomId(entity.getElderId());
        }
        checkoutApplicationMapper.updateById(entity);


    }
}
